import { ChannelType, getChannelListAPI } from "@/apis/articleApi";
import { useEffect, useState } from "react";

const useChannel = function () {
    // 频道信息
    const [channels, setChannels] = useState<Array<ChannelType>>([]);

    // 获取频道信息
    useEffect(() => {
        const { request, controller } = getChannelListAPI();
        request.then(response => {
            setChannels(response.data.channels);
        });
        return () => {
            controller.abort();
        };
    }, []);

    return { channels };
};

export default useChannel;